<div class="layui-fluid" style="top: 0;padding-top: 0">
    <div class="layui-col-xs12" style="height: 474px;overflow-y: auto;">
        <div class="layui-card">
            <div class="layui-card-body">
                <form class="layui-form resAddForms" action="" lay-filter="resAddForms">
                    <div class="layui-form-item">
                        <div class="layui-input-block" style="margin:0;">
                            <a lay-submit lay-filter="resAddForm" class="layui-btn">保存</a>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">资源名称:<span style="color:red">*</span></label>
                        <div class="layui-input-block">
                            <input type="text" name="resName" autocomplete="off"
                                   class="layui-input resNames" maxlength="32" lay-verify="required|names">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">资源别名:<span style="color:red">*</span></label>
                        <div class="layui-input-block">
                            <input type="text" name="alias" maxlength="32" autocomplete="off"
                                   class="layui-input alias" lay-verify="required|alias">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">资源图标:</label>
                        <div class="layui-input-block" style="line-height: 36px">
                            <i class="iconfont" id="iconShow"></i>
                            <span class="layui-btn iconSelect">请选择</span>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">默认地址:</label>
                        <div class="layui-input-block">
                            <input type="text" class="layui-input" name="defaultUrl" id="defaultUrl" lay-verify="defaultUrl">
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <label class="layui-form-label">是否有子节点:</label>
                        <div class="layui-input-block">
                            <input type="radio" name="isFolder" value="1" title="是" checked>
                            <input type="radio" name="isFolder" value="0" title="否">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">显示到菜单:</label>
                        <div class="layui-input-block">
                            <input type="radio" name="isDisplayInMenu" value="1" title="是" checked>
                            <input type="radio" name="isDisplayInMenu" value="0" title="否">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">默认打开:</label>
                        <div class="layui-input-block">
                            <input type="radio" name="isOpen" value="1" title="是" checked>
                            <input type="radio" name="isOpen" value="0" title="否">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">是否打开新窗口:</label>
                        <div class="layui-input-block">
                            <input type="radio" name="isNewOpen" value="1" title="是">
                            <input type="radio" name="isNewOpen" value="0" title="否" checked>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">同级排序:<span style="color:red">*</span></label>
                        <div class="layui-input-block">
                            <input type="text" name="sn" class="layui-input" lay-verify="required|sort">

                        </div>
                    </div>
                    <div class="layui-form-item">
                        开发过程的辅助功能，后期删除
                    </div>

                    <div class="layui-form-item">
                        <label class="layui-form-label">正式菜单:</label>
                        <div class="layui-input-block">
                            <input type="radio" name="official" value="1" title="是" checked>
                            <input type="radio" name="official" value="0" title="否">
                        </div>
                        如果是正式的平台功能，请选择是，否则选择否。选择是，创建人ID会是999999999，方便菜单整理
                    </div>

                    <div class="layui-form-item">
                        <label class="layui-form-label">roleType:</label>
                        <div class="layui-input-block">
                            <input type="text" name="roleType" class="layui-input" placeholder="1:系统管理员，2:安全保密管理员，3:审计员，多个用逗号分隔">
                        </div>
                    </div>
                    <input type="text" name="parentId" class="layui-input layui-hide">
                    <input type="text" name="systemId" class="layui-input layui-hide">
                </form>
            </div>
        </div>
    </div>
</div>
<script>


    layui.use(['form', 'layer', 'table', 'commons', 'setter', 'jquery'], function () {
        var form = layui.form, layer = layui.layer, commons = layui.commons, setter = layui.setter, $ = layui.jquery;
        form.render();
        var menuIndex = parent.layer.getFrameIndex(window.name);
        form.verify(commons.formVerify);
        $("#defaultUrl").val(serverPath.formPath + setter.formLinkPath +"dataTemplate/view/preview?formKey=${formKey}");
        form.on('submit(resAddForm)', function (data) {
            var iconClassName = "";
            iconClassName = $('#iconShow').attr('class').trim().split(" ");
            data.field.iconSkin = iconClassName[2];
            if (selectResId == "") {
                layer.alert("请从左边的资源树上选择父节点！");
                return false;
            }
            data.field.parentId = selectResId;
            $.ajax({
                url: serverPath.formPath + setter.sysLinkPath + "sysRes/add",
                type: "POST",
                dataType: 'json',
                data: data.field,
                success: function (data) {
                    if (commons._filterRecord(data)) {
                        layer.alert(data.msg,function(index){
                            layer.close(index);
                            parent.layer.closeAll();
                        });
                    } else {
                        window.parent.layer.alert(data.msg);
                    }
                }
            });
        });

        $(".iconSelect").click(function () {
            layer.open({
                type: 2,
                area: ['860px', '505px'],
                title: ['选择图标'],
                content: serverPath.formPath + setter.sysLinkPath + 'sysRes/view/icons'
            });
        });
        //自动生成别名
        $(".resNames").change(function () {
            var str = $(this).val();
            if (str == "") return;
            var arrRslt = component.chineseToPinyinAlias(str);
            $(".alias").val(arrRslt[0]);
        });
    })
</script>